﻿using System;
using System.Collections;
using System.Threading;
using UnityEngine;

namespace Framework
{
    public class ThreadHelper 
    {
        public static IEnumerator Start(Func<object> action)
        {
            Action<object> doAction = (object obj) => {
                int retTaskId = (int)obj;
                object ret = action();
                CoroutineDecorator.Instance.Callback(retTaskId, ret);
            };
            
            yield return new GetTid();
            int taskId = (int)CoroutineDecorator.Instance.returnValueRegister;
            ThreadPool.QueueUserWorkItem(new WaitCallback(doAction), taskId);
            yield return new Sleep(taskId, -1);
        }
    }
}

